package controller;

import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Page;

import config.Consts;
import util.DataTable;

public class BaseController extends Controller {

	protected void renderDataTable(Page page){
		DataTable dataTable = new DataTable(getParaToInt("draw"),page.getTotalRow(),page.getTotalRow(),page.getList());
		renderJson(dataTable);
	}

	protected int getPageNumber() {
		int start = getParaToInt("start", 0);
		if(start < 0){
			start = 0;
		}
		return start / getPageSize() + 1;
	}

	protected int getPageSize() {
		int size = getParaToInt("length", 10);
		if (size < 1) {
			size = 1;
		}
		return size;
	}
	
	protected int getRole(){
		return (Integer)getSession().getAttribute(Consts.SESSION_USER_ROLE);
	}
	
	protected Long getUserId(){
		return (Long)getSession().getAttribute(Consts.SESSION_USER_ID);
	}

}
